package com.code.config;

import com.code.bean.User;
import com.code.service.MyService;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Controller;

/**
 * 注解配置==配置文件
 *
 * @author wangjie
 * @version V1.0
 * @date 2020/1/5
 */
@Configuration
//@ComponentScan  value:指定要扫描的包
//excludeFilters = Filter[] ：指定扫描的时候按照什么规则排除那些组件
//includeFilters = Filter[] ：指定扫描的时候只需要包含哪些组件
//FilterType.ANNOTATION：按照注解
//FilterType.ASSIGNABLE_TYPE：按照给定的类型；
//FilterType.ASPECTJ：使用ASPECTJ表达式
//FilterType.REGEX：使用正则指定
//FilterType.CUSTOM：使用自定义规则
@ComponentScan(value="com.code",includeFilters = {
        @Filter(type=FilterType.ANNOTATION,classes={Controller.class}),
        @Filter(type= FilterType.ASSIGNABLE_TYPE,classes={MyService.class}),
        @Filter(type=FilterType.CUSTOM,classes={MyTypeFilter.class})
},useDefaultFilters = false)
@ComponentScans(value = {
        @ComponentScan(value="com.code",includeFilters = {
                @Filter(type=FilterType.ANNOTATION,classes={Controller.class}),
                @Filter(type= FilterType.ASSIGNABLE_TYPE,classes={MyService.class}),
                @Filter(type=FilterType.CUSTOM,classes={MyTypeFilter.class})
        },useDefaultFilters = false)
})
public class MyConfig {

    /**
     * 给容器注册一个bean,id默认为方法名
     * @return  {@link User}
     */
    @Bean
    public User user(){
        return new User("wangjie",18);
    }
}
